<?php
session_start ();
// 判断用户是否已经登录
if (! isset ( $_SESSION ["userinfo"] ) and empty ( $_SESSION ["userinfo"] ["userid"] )) {
	header ( "location:../index.php" );
	session_unset ();
	session_destroy ();
	exit ();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="zh-CN">
<link href="./Resource/Style/base.yy.css" rel="stylesheet"
	type="text/css">
<link href="./Resource/Style/info.yy.css" rel="stylesheet"
	type="text/css">
</head>
<body>
<?php
require_once '../tools/SqlHelper.class.php';
if (isset ( $_POST ['user_submit'] ) and $_POST ['user_submit'] == '确认修改') {
	// 获取浏览器发过来的页面数据
	$password = $_POST ['password'];
	$newPass = $_POST ['newPass'];
	if ($newPass == "") {
		echo "<script>alert('新密码不能为空')</script>";
	} else if (strlen ( $newPass ) < 6) {
		echo "<script>alert('新密码不能小于6位')</script>";
	} else {
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$user_id = $_SESSION ["userinfo"] ["userid"];
		// $user_id = "xufeng520";
		$sql = "select * from `user_tb` where `user_id`='$user_id'";
		$res = $sqlHelper->execute_dql ( $sql );
		$row = mysql_fetch_array ( $res );
		if ($row ['user_password'] == md5 ( $password )) {
			$result2 = $sqlHelper->execute_dql ( "UPDATE `user_tb` SET `user_password`=md5('$newPass') WHERE `user_id`='$user_id'" );
			if (! ! $result2) {
				echo "<script>alert('修改密码成功')</script>";
			} else {
				echo "<script>alert('修改密码失败')</script>";
			}
		} else {
			echo "<script>alert('原始密码错误')</script>";
		}
		// 关闭连接
		// mysql_free_result ( $res );
		$sqlHelper->close_connect ();
	}
}
?>
	<nav>
		<div class="info_nav">
			<ul>
				<li><a href="./baseData.php">基本资料</a></li>
				<li><a href="./Details.php">详细资料</a></li>
				<li><a href="./soliloquy.php">内心独白</a></li>
				<li><a href="./uploadingPhoto.php">上传头像</a></li>
				<li><a href="./myPhoto.php">我的相册</a></li>
				<li><a href="./PersonalCondition.php">征友条件</a></li>
				<li><a class="a_out" href="#">修改密码</a></li>
				<li class="last"><a href="#"></a></li>
			</ul>
		</div>
	</nav>
	<div class="info_con">
		<div class="change">
			<form id="changePassWord" name="changePassWord"
				action="changePassword.php" method="post">
				<ul>
					<li><label>当前密码：</label><input name="password" id="password"
						maxlength="20" type="password"><strong id="passMsg"
						style="display: none;" class="orange"></strong></li>
					<li><label>新密码：</label><input maxlength="10" name="newPass"
						id="newPass" type="password"><strong id="newPassMsg"
						style="display: none;" class="orange"></strong></li>
					<li class="li_smsll"><label>&nbsp;</label><span>*&nbsp;请设置3-10位数字或字母作为密码</span></li>
					<li><label>&nbsp;</label> <input class="change_ul_li_input2"
						name="user_submit" type="submit" value="确认修改" /></li>
				</ul>
			</form>
		</div>
	</div>
</body>
</html>